package com.chendechao.model_home.ui.recommend.comment


import androidx.lifecycle.ViewModel
import com.chendechao.lib_base.BaseViewModel
import com.chendechao.model_home.model.RecommendMutilVideo
import com.chendechao.model_home.ui.recommend.RecommendIntent
import com.chendechao.model_home.ui.recommend.RecommendUIState

import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class SendCommentViewModel @Inject constructor(val repository: CommentRepository): BaseViewModel<SendCommentUIState, SendCommentIntent>(SendCommentUIState()) {
    override suspend fun handleEvent(event: SendCommentIntent) {
        when (event) {
            is SendCommentIntent.LoadData -> loadData()
        }
    }

    private suspend fun loadData() {

        val json = """{"comment": "这是一条评论", "videoId": "12345"}"""
        val requestBody = RequestBody.create("application/json".toMediaType(), json)
        val res = repository.postSendCommentData(requestBody)


        res.onSuccess {
            updateState(SendCommentUIState(SendcomentData = it.SendcomentData,  isSucess = true))
        }.onFailure {

        }
    }




}